package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.TeacherPerformance;
import com.ruoyi.system.service.ITeacherPerformanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 教师绩效类型Controller
 * 
 * @author bearzz
 * @date 2024-01-22
 */
@RestController
@RequestMapping("/performance")
public class TeacherPerformanceController extends BaseController
{
    @Autowired
    private ITeacherPerformanceService teacherPerformanceService;

    /**
     * 查询教师绩效类型列表
     */
    @RequiresPermissions("teacher:performance:list")
    @GetMapping("/list")
    public TableDataInfo list(TeacherPerformance teacherPerformance)
    {
        startPage();
        List<TeacherPerformance> list = teacherPerformanceService.selectTeacherPerformanceList(teacherPerformance);
        return getDataTable(list);
    }

    /**
     * 导出教师绩效类型列表
     */
    @RequiresPermissions("teacher:performance:export")
    @Log(title = "教师绩效类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeacherPerformance teacherPerformance)
    {
        List<TeacherPerformance> list = teacherPerformanceService.selectTeacherPerformanceList(teacherPerformance);
        ExcelUtil<TeacherPerformance> util = new ExcelUtil<TeacherPerformance>(TeacherPerformance.class);
        util.exportExcel(response, list, "教师绩效类型数据");
    }

    /**
     * 获取教师绩效类型详细信息
     */
    @RequiresPermissions("teacher:performance:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(teacherPerformanceService.selectTeacherPerformanceById(id));
    }

    /**
     * 新增教师绩效类型
     */
    @RequiresPermissions("teacher:performance:add")
    @Log(title = "教师绩效类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeacherPerformance teacherPerformance)
    {
        return toAjax(teacherPerformanceService.insertTeacherPerformance(teacherPerformance));
    }

    /**
     * 修改教师绩效类型
     */
    @RequiresPermissions("teacher:performance:edit")
    @Log(title = "教师绩效类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeacherPerformance teacherPerformance)
    {
        return toAjax(teacherPerformanceService.updateTeacherPerformance(teacherPerformance));
    }

    /**
     * 删除教师绩效类型
     */
    @RequiresPermissions("teacher:performance:remove")
    @Log(title = "教师绩效类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(teacherPerformanceService.deleteTeacherPerformanceByIds(ids));
    }
}
